package com.gegao.somethinginteresting.utils.fresco.builder;

import android.graphics.drawable.Drawable;

import com.gegao.somethinginteresting.utils.fresco.FRESCOURITYPE;
import com.gegao.somethinginteresting.utils.fresco.callback.FrescoBitmapCallback;


/**
 * fresco的请求构建
 * Created by liuchenghui on 2016/01/06.
 */
public abstract class FrescoRequestBuilder {

    protected String mUrl;
    protected FRESCOURITYPE mUrlType;
    protected int mWidth;
    protected int mHeight;
    protected Drawable mHolder;
    protected boolean isClearCache;
    protected String mPackageName;
    protected FrescoBitmapCallback mFrescoBitmapCallback;


    /**
     * 设置加载图片的url
     * @param url 加载的地址
     */
    public FrescoRequestBuilder url(String url) {
        this.mUrl = url;
        return this;
    }

    /**
     * 设置加载图片的url
     * @param resourceId 加载的资源文件Id(urlType:默认设置为{@link FRESCOURITYPE#RESOURCEURI})
     */
    public FrescoRequestBuilder url(int resourceId) {
        this.mUrl = String.valueOf(resourceId);
        this.mUrlType = FRESCOURITYPE.RESOURCEURI;
        return this;
    }

    /**
     * 设置加载url的类型
     * @param urlType url的类型 {@link FRESCOURITYPE}
     */
    public FrescoRequestBuilder setUrlType(FRESCOURITYPE urlType) {
        this.mUrlType = urlType;
        return this;
    }

    /**
     * 重置高宽
     * @param width 重置的宽
     * @param height 重置的高
     */
    public FrescoRequestBuilder resize(int width, int height) {
        this.mWidth = width;
        this.mHeight = height;
        return this;
    }

    /**
     * 设置占位图
     * @param holder 占位图
     */
    public FrescoRequestBuilder placeHolder(Drawable holder) {
        this.mHolder = holder;
        return this;
    }

    /**
     * 是否不需要缓存
     */
    public FrescoRequestBuilder withOutCache(boolean clearCache, String packageName) {
        this.isClearCache = clearCache;
        this.mPackageName = packageName;
        return this;
    }
    /**
     * 设置加载图片的回调(可以修改返回的bitMap,修改会在显示在控件中)
     *
     * @param frescoBitmapCallback 回调
     */
    public FrescoRequestBuilder getImage(final FrescoBitmapCallback frescoBitmapCallback) {
        this.mFrescoBitmapCallback = frescoBitmapCallback;
        return this;
    }

    /**
     * 开始构建
     */
    public abstract void build();
}